package edu.hlju.lms.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author Toya
 * @PackageName:edu.hlju.lms.utils
 * @ClassName: SessionUtil
 * @Description:
 * @date 2021/11/26 9:29
 */
public class SessionUtil {

    private static SqlSessionFactory sqlSessionFactory;
    private static InputStream inputStream;

    public static SqlSession getSession() {
        String resource = "config.xml";
        inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            e.printStackTrace();
        }
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        SqlSession session = sqlSessionFactory.openSession();

        return session;
    }
}
